From: tsteven4 Date: Sat, 8 Aug 2015 15:49:15 +0000 (-0600) Subject: fix bug with xcsv format and utm zone character input. X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2~10^2~6^2~8^2~6^2~1 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=2df8b9f4b376f83d1ae6a17238cb91f4e4a91d48;p=gpsbabel.git fix bug with xcsv format and utm zone character input. enhance xcsv format reader to use unknown altitude if the an altitude input conversion has an error. --- diff --git a/gpsbabel/csv_util.cc b/gpsbabel/csv_util.cc index 70510f29f..3304ae4a5 100644 --- a/gpsbabel/csv_util.cc +++ b/gpsbabel/csv_util.cc @@ -1101,7 +1101,7 @@ xcsv_parse_val(const char* s, Waypoint* wpt, const field_map_t* fmp, utm_zone = atoi(s); break; case XT_UTM_ZONEC: - utm_zonec = atoi(s); + utm_zonec = s[0]; break; case XT_UTM_ZONEF: utm_zone = atoi(s); @@ -1128,20 +1128,36 @@ xcsv_parse_val(const char* s, Waypoint* wpt, const field_map_t* fmp, } break; /* ALTITUDE CONVERSIONS ************************************************/ - case XT_ALT_FEET: + case XT_ALT_FEET: { /* altitude in feet as a decimal value */ - wpt->altitude = FEET_TO_METERS(atof(s)); - if (wpt->altitude < unknown_alt + 1) { + double val; + char *endptr; + val = strtod(s, &endptr); + if ((val == 0 && s==endptr)) { wpt->altitude = unknown_alt; + } else { + wpt->altitude = FEET_TO_METERS(val); + if (wpt->altitude < unknown_alt + 1) { + wpt->altitude = unknown_alt; + } } - break; - case XT_ALT_METERS: + } + break; + case XT_ALT_METERS: { /* altitude in meters as a decimal value */ - wpt->altitude = atof(s); - if (wpt->altitude < unknown_alt + 1) { + double val; + char *endptr; + val = strtod(s, &endptr); + if ((val == 0 && s==endptr)) { wpt->altitude = unknown_alt; + } else { + wpt->altitude = val; + if (wpt->altitude < unknown_alt + 1) { + wpt->altitude = unknown_alt; + } } - break; + } + break; /* PATH CONVERSIONS ************************************************/ case XT_PATH_SPEED: diff --git a/gpsbabel/reference/grid-utm~xscv.gpx b/gpsbabel/reference/grid-utm~xscv.gpx new file mode 100644 index 000000000..4402fe601 --- /dev/null +++ b/gpsbabel/reference/grid-utm~xscv.gpx @@ -0,0 +1,174 @@ + + + + + + + "Wpt_12E7vrv" + "Wpt_12E7vrv" + "Wpt_12E7vrv" + + + 57.000000 + + "Wpt_1NAeS" + "Wpt_1NAeS" + "Wpt_1NAeS" + + + + "Wpt_2BYa1" + "Wpt_2BYa1" + "Wpt_2BYa1" + + + 83.000000 + + "Wpt_32sd" + "Wpt_32sd" + "Wpt_32sd" + + + 36.000000 + + "Wpt_39vH4Z" + "Wpt_39vH4Z" + "Wpt_39vH4Z" + + + + "Wpt_5tD1wEB" + "Wpt_5tD1wEB" + "Wpt_5tD1wEB" + + + + "Wpt_5Zhkd" + "Wpt_5Zhkd" + "Wpt_5Zhkd" + + + 23.000000 + + "Wpt_6irYN" + "Wpt_6irYN" + "Wpt_6irYN" + + + 83.000000 + + "Wpt_A1ss" + "Wpt_A1ss" + "Wpt_A1ss" + + + + "Wpt_APJU5" + "Wpt_APJU5" + "Wpt_APJU5" + + + + "Wpt_ASbe" + "Wpt_ASbe" + "Wpt_ASbe" + + + 67.000000 + + "Wpt_eT3d" + "Wpt_eT3d" + "Wpt_eT3d" + + + 37.000000 + + "Wpt_HbL58" + "Wpt_HbL58" + "Wpt_HbL58" + + + 15.000000 + + "Wpt_Hupm" + "Wpt_Hupm" + "Wpt_Hupm" + + + 55.000000 + + "Wpt_i61vHHf" + "Wpt_i61vHHf" + "Wpt_i61vHHf" + + + 42.000000 + + "Wpt_IKcJ" + "Wpt_IKcJ" + "Wpt_IKcJ" + + + 23.000000 + + "Wpt_j0344" + "Wpt_j0344" + "Wpt_j0344" + + + 92.000000 + + "Wpt_MedoTEJ" + "Wpt_MedoTEJ" + "Wpt_MedoTEJ" + + + 47.000000 + + "Wpt_Q6qCFNf3" + "Wpt_Q6qCFNf3" + "Wpt_Q6qCFNf3" + + + 2.000000 + + "Wpt_Qkfl" + "Wpt_Qkfl" + "Wpt_Qkfl" + + + 6.000000 + + "Wpt_qzkKBpz" + "Wpt_qzkKBpz" + "Wpt_qzkKBpz" + + + 51.000000 + + "Wpt_r81J0Qr" + "Wpt_r81J0Qr" + "Wpt_r81J0Qr" + + + 13.000000 + + "Wpt_tzplq3SA" + "Wpt_tzplq3SA" + "Wpt_tzplq3SA" + + + 10.000000 + + "Wpt_vhagfqH" + "Wpt_vhagfqH" + "Wpt_vhagfqH" + + + 51.000000 + + "Wpt_ZHNuvzhQ" + "Wpt_ZHNuvzhQ" + "Wpt_ZHNuvzhQ" + + diff --git a/gpsbabel/testo.d/xcsv.test b/gpsbabel/testo.d/xcsv.test index 9cf8b9f94..76fac4a4b 100644 --- a/gpsbabel/testo.d/xcsv.test +++ b/gpsbabel/testo.d/xcsv.test @@ -15,3 +15,20 @@ gpsbabel -i geo -f ${REFERENCE}/../geocaching.loc -o xcsv,style=${TMPDIR}/testo. gpsbabel -i xcsv,style=${TMPDIR}/testo.style -f ${TMPDIR}/xcsv.geo -o xcsv,style=${TMPDIR}/testo.style -F ${TMPDIR}/xcsv.xcsv compare ${TMPDIR}/xcsv.geo ${TMPDIR}/xcsv.xcsv +echo "FIELD_DELIMITER COMMA" > ${TMPDIR}/testo2.style +echo "RECORD_DELIMITER NEWLINE" >> ${TMPDIR}/testo2.style +echo "BADCHARS COMMA" >> ${TMPDIR}/testo2.style +echo "PROLOGUE No,UTM-Zone,UTM-Ch,UTM-East,UTM-North,Name,Altitude,Symbol,Date,Time" >> ${TMPDIR}/testo2.style +echo "IFIELD IGNORE, , %s" >> ${TMPDIR}/testo2.style +echo "IFIELD UTM_ZONE, , %d" >> ${TMPDIR}/testo2.style +echo "IFIELD UTM_ZONEC, , %c" >> ${TMPDIR}/testo2.style +echo "IFIELD UTM_EASTING, , %.0f" >> ${TMPDIR}/testo2.style +echo "IFIELD UTM_NORTHING, , %.0f" >> ${TMPDIR}/testo2.style +echo "IFIELD SHORTNAME, , %s" >> ${TMPDIR}/testo2.style +echo "IFIELD ALT_METERS, -99999999.0, %.0f" >> ${TMPDIR}/testo2.style +echo "IFIELD IGNORE, , %s" >> ${TMPDIR}/testo2.style +echo "IFIELD GMT_TIME, , %Y/%m/%d" >> ${TMPDIR}/testo2.style +echo "IFIELD HMSG_TIME, , %d:%d:%d" >> ${TMPDIR}/testo2.style +rm -f ${TMPDIR}/grid-utm~xscv.gpx +gpsbabel -i xcsv,style=${TMPDIR}/testo2.style -f ${REFERENCE}/grid-utm.csv -o gpx -F ${TMPDIR}/grid-utm~xscv.gpx +compare ${TMPDIR}/grid-utm~xscv.gpx ${REFERENCE}/grid-utm~xscv.gpx